package com.example.springboottools.gms;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Date;

public class DateToTimestampSerializer implements ObjectSerializer {
    @Override
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        if (object instanceof Date) {
            long timestamp = ((Date) object).getTime();
            serializer.write(timestamp);
        } else {
            serializer.writeNull();
        }
    }
}
